<#assign  title="地址列表" />
<#include 'common/header.html'>
<#assign memberLoginCheckTag = newTag("memberLoginCheckTag") />
<#assign memberInfo = memberLoginCheckTag() />
<!--创建"会员地址列表"标签-->
<#assign consigneeListTag= newTag("consigneeListTag") >    
<!--调用"会员地址列表"标签-->          
<#assign  consigneeList= consigneeListTag()>	
<#assign regionSelect = "com.enation.app.shop.front.tag.goods.other.regions.RegionSelectDirective"?new()>
<link rel="stylesheet" type="text/css" href="themes/wap/css/member.css" />
<div class="header-tools">
	<div class="go-back">
		<a href="javascript:" onclick="window.history.go(-1)"></a>
	</div>
	<div class="common-title">
		地址列表
	</div>
	<div class="go-search">
	</div>
</div>
<div class="adresslist">
	<ul>
	<#if consigneeList?size gt 0 >
		<#list consigneeList as address>
			<li class="addresslist">
				<div class="addresslist_left" rel="${address.addr_id}">
						<div class="adressintro">
							<p><span class="list_title">姓名：</span><span>${address.name!''}</span></p>
							<p><span class="list_title">电话：</span><span>${address.mobile!''}</span></p>
							<p><span class="list_title">地址：</span><span>${address.province!''}-${address.city!''}-${address.region!''}-${address.addr!''}</span></p>
						</div>
				</div>
				<div class="addresslist_right">
					<p class="isdef_addr" rel="${address.addr_id}"><#if address.def_addr == 1 >默认地址<#else>设为默认</#if></p>
					<a href="edit_address.html?addressid=${address.addr_id}&back=${back}" class="go_addedit"></a>
					<a href="javascript:;" rel="${address.addr_id}" class="detele_add"></a>
				</div>
			</li>
		</#list>
	<#else>
			<li style="text-align:center;">您尚未添加收货地址</li>
	</#if>
	</ul>
</div>
<div class="new_address">
	<a href="javascript:;" class="addressadd">添加一个</a>
</div>
<!--输出列表 -->
<script>
//根据参数名称获得值函数
function getUrlParam(strname) {  
    var hrefstr, pos, parastr, para, tempstr;  
    hrefstr = window.location.href;  
    pos = hrefstr.indexOf("?");  
    parastr = hrefstr.substring(pos + 1);  
    para = parastr.split("&");  
    tempstr = "";  
    for (i = 0; i < para.length; i++) {  
        tempstr = para[i];  
        pos = tempstr.indexOf("=");  
        if (tempstr.substring(0, pos) == strname) {  
            return tempstr.substring(pos + 1).replace("#", "");  
        }  
    }  
    return null;  
}  
function newaddress (){
	var new_address=getUrlParam("back");
	location.href="address.html?back="+new_address;
}
$(function(){
//删除地址
$(".detele_add").click(function(){
	var deteleid = $(this).attr("rel");
	
	if (!confirm("确认要将此地址删除吗？")) {
		return;
	}
	
	$.ajax({
		url:"api/shop/member-address/delete.do?addr_id="+deteleid,
		dataType:"json",
		success:function(result){
			if(result.result==1){
				alert(result.message);
				location.reload();
			}else{
				$.alert(result.message);
			}
		},error:function(){
			alert("抱歉，解冻出错现意外错误");
		}
	});		
})

$(".go_back").click(function(){
	var go_back=getUrlParam("back");
	if(go_back==1||go_back==null){
		location.href="member.html";
	}
	else if(go_back==2){
		location.href="checkout.html";
	}
})
//到新建地址路径函数
$(".new_address").click(function(){
	newaddress();
})


function isaddr(addrid){
	$.post("${ctx}"+"/api/shop/member-address/isdefaddr.do",{"addr_id":addrid},function(result){
		if(result.result==1){				
			var goReturn=  getUrlParam("back");
			if(goReturn==1){
				location.href="addresslist.html?back=1";
			}
			else if(goReturn==2){
				location.href="${ctx}/checkout/checkout.html"
			}
			
		}
		
		else{				
			alert(result.message);
		}			
	},"json");
}

//设置为默认地址
$(".isdef_addr").click(function(){
	var addrid = $(this).attr("rel");
	isaddr(addrid);
})
$(".addresslist_left").click(function(){
	var addrid = $(this).attr("rel");
	isaddr(addrid);
})


})
</script>
<#include 'common/float_footer.html'/>
<#include 'common/footer.html'/>